package ynu.edu.elmspringboot.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ynu.edu.elmspringboot.po.Food;
import ynu.edu.elmspringboot.service.FoodService;

import java.util.List;

@RestController
@RequestMapping("/FoodController")
public class FoodController {

    @Autowired
    private FoodService foodService;

    @PostMapping("/listFoodByBusinessId")
    public List<Food> listFoodByBusinessId(Food food) {
        QueryWrapper<Food> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("business_id", food.getBusinessId())
                .orderByAsc("food_id");
        return foodService.list(queryWrapper);
    }

    @PostMapping("/getFoodById")
    public Food getFoodById(Integer foodId) {
        return foodService.getById(foodId);
    }

}